<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
		<meta name="theme-color" content="#4b75ff">
		<link rel="stylesheet" href="../script/semantic/semantic.min.css">
		<script src="../script/jquery.min.js"></script>
		<script src="../script/ao_module.js"></script>
		<script src="../script/semantic/semantic.min.js"></script>
        <script src="message.js"></script>
		<link rel="icon" type="image/png" href="img/module_icon.png">
		<link rel="manifest" crossorigin="use-credentials" href="manifest.json">
		<title>OfficeViewer</title>
		<style>
            body{
                border-top: 5px solid #445b80;
                background-color: white;
            }
		</style>
	</head>
	<body>
        <br>
        <div class="ui container">
            <button class="ui basic fluid button" onclick="openFileSelector();">Open File</button>
            <div class="ui divider"></div>
            ArozOS Office Viewer
        </div>
		<script>
            $(document).ready(function(){
                openFileSelector();
            });

            function openFileSelector(){
                ao_module_openFileSelector(fileSelected, "user:/Document", "file",false, {
                    filter: ["docx", "pptx", "xlsx"]
                });
            }

            function fileSelected(filedata){
                if (filedata.length == 0){
                    alert("No file selected")
                }else{
                    console.log(encodeURIComponent(JSON.stringify(filedata)));
                    ao_module_setWindowSize(1060, 680);
                    let redirectionURL = "embedded.html#" + encodeURIComponent(JSON.stringify(filedata));
                    if (window.location.href.substr(window.location.href.length - 1) != "/"){
                        redirectionURL = "/" + redirectionURL;
                    }
                    window.location.href= window.location.href + redirectionURL;
                }
            }
		</script>
	</body>
</html>